home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / tcqbsnip.zip / RECRDREF.BAS < prev    next >
BASIC Source File  |  1997-06-20  |  1KB  |  62 lines

  1. ' Passing Records by Reference
  2. ' by Tika Carr
  3. ' May 7, 1997
  4. '
  5. ' Notice how you can pass a record to a sub and have it returned changed.
  6. ' Another useful way to eliminate the need for global variables! And, you
  7. ' won't need to worry about that record being altered by any other routine
  8. ' other than the one that is supposed to alter it.
  9.  
  10. DECLARE SUB another ()
  11. DECLARE SUB test (ret AS ANY, flag$)
  12.  
  13. DEFINT A-Z
  14.  
  15. TYPE inftst
  16.   x AS INTEGER
  17.   y AS INTEGER
  18.   b AS INTEGER
  19. END TYPE
  20.  
  21. DIM var AS inftst
  22.  
  23. CLS
  24.  
  25. PRINT "Round 1: Parameter = one"
  26. test var, "one"
  27. PRINT
  28. PRINT "x = "; var.x, "y = "; var.y, "b ="; var.b
  29. PRINT
  30. another
  31. PRINT "Round 2: Parameter = two"
  32. test var, "two"
  33. PRINT
  34. PRINT "x = "; var.x, "y = "; var.y, "b ="; var.b
  35. PRINT
  36. another
  37. END
  38.  
  39. SUB another
  40.  
  41. 'I purposely named this the same as in the test sub, to show you it will
  42. '_NOT_ keep the values:
  43. DIM ret AS inftst
  44.  
  45. PRINT "Meanwhile, inside 'another' function:"
  46. PRINT "x = "; ret.x, "y ="; ret.y, "b ="; ret.b
  47. PRINT
  48. END SUB
  49.  
  50. SUB test (ret AS inftst, flag$) STATIC
  51.  
  52. IF flag$ = "one" THEN
  53.   ret.x = 1: ret.y = 1: ret.b = 0
  54. END IF
  55.  
  56. IF flag$ = "two" THEN
  57.   ret.x = 2: ret.y = 2: ret.b = 1
  58. END IF
  59.  
  60. END SUB
  61.  
  62.